{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "import pandas as pd\r\n",
    "import numpy as np"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "print(\"a\")"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "a\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "# series的创建 \r\n",
    "# series是一位数据结构\r\n",
    "s1 = pd.Series([1,2,3,4,5,])\r\n",
    "s1"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "3    4\n",
       "4    5\n",
       "dtype: int64"
      ]
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "source": [
    "# 通过数组创建\r\n",
    "arr1 = np.arange(1,6)\r\n",
    "arr1\r\n",
    "s2 = pd.Series(arr1)\r\n",
    "s2"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "3    4\n",
       "4    5\n",
       "dtype: int32"
      ]
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "# 更改索引\r\n",
    "s2 = pd.Series(arr1,index=['a','b','c','d','e'])\r\n",
    "s2"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "d    4\n",
       "e    5\n",
       "dtype: int32"
      ]
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "source": [
    "# Series的基本用法\r\n",
    "s2.isnull()\r\n",
    "s2.notnull()\r\n",
    "print(s2.index)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Index(['a', 'b', 'c', 'd', 'e'], dtype='object')\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "# 获取某一行 通过下标 通过标签名\r\n",
    "s2[1]\r\n",
    "s2['b']\r\n",
    "s2[['b','c']] # 取多个\r\n",
    "s2[1:2] #切片取值 一样的前闭后开\r\n",
    "s2['b':'c'] # 标签切片 前闭后闭\r\n",
    "s2[s2>3] # 布尔索引"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "d    4\n",
       "e    5\n",
       "dtype: int32"
      ]
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "s2*2"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "a     2\n",
       "b     4\n",
       "c     6\n",
       "d     8\n",
       "e    10\n",
       "dtype: int32"
      ]
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "source": [
    "s2.head() # 默认查看前5行\r\n",
    "s2.head(3) # 指定选择前3行"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "a    1\n",
       "b    2\n",
       "c    3\n",
       "dtype: int32"
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "# DataFrame是表格数据结构\r\n",
    "# 利用字典构造\r\n",
    "data = {'a': [1,2,3,4],\r\n",
    "        'b': (5,6,7,8),\r\n",
    "        'c': np.arange(9,13)}\r\n",
    "frame = pd.DataFrame(data)\r\n",
    "frame"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   a  b   c\n",
       "0  1  5   9\n",
       "1  2  6  10\n",
       "2  3  7  11\n",
       "3  4  8  12"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 10
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "source": [
    "# 查看行，列索引， 查看值\r\n",
    "frame.index\r\n",
    "frame.columns\r\n",
    "frame.values"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([[ 1,  5,  9],\n",
       "       [ 2,  6, 10],\n",
       "       [ 3,  7, 11],\n",
       "       [ 4,  8, 12]], dtype=int64)"
      ]
     },
     "metadata": {},
     "execution_count": 11
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "source": [
    "# 指定列索引\r\n",
    "frame = pd.DataFrame(data, index=['A','B','C','D'],columns=['a','b','c','d'])\r\n",
    "frame"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   a  b   c    d\n",
       "A  1  5   9  NaN\n",
       "B  2  6  10  NaN\n",
       "C  3  7  11  NaN\n",
       "D  4  8  12  NaN"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "      <th>d</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>12</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "source": [
    "arr1 = np.arange(12).reshape(4,3)\r\n",
    "frame1 = pd.DataFrame(arr1)\r\n",
    "frame1"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   0   1   2\n",
       "0  0   1   2\n",
       "1  3   4   5\n",
       "2  6   7   8\n",
       "3  9  10  11"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 13
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "source": [
    "# 转置\r\n",
    "frame1.T"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   0  1  2   3\n",
       "0  0  3  6   9\n",
       "1  1  4  7  10\n",
       "2  2  5  8  11"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>7</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>8</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 14
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "source": [
    "frame1[:1]\r\n",
    "frame1[0]  # 切片操作与之前的相同"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "0    0\n",
       "1    3\n",
       "2    6\n",
       "3    9\n",
       "Name: 0, dtype: int32"
      ]
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "source": [
    "# 查看行  行索引\r\n",
    "frame1[0]\r\n",
    "frame1[0:2] # 位置切片\r\n",
    "frame1[0:2] # 标签索引 按索引名前闭后闭\r\n",
    "frame1[[0,2]] # 不连续索引\r\n",
    "frame1[frame1>2] # 布尔索引"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "     0     1     2\n",
       "0  NaN   NaN   NaN\n",
       "1  3.0   4.0   5.0\n",
       "2  6.0   7.0   8.0\n",
       "3  9.0  10.0  11.0"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6.0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>9.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 25
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "source": [
    "# 列索引\r\n",
    "frame1[[1]] # 两个中括号就是列索引\r\n",
    "frame1.loc[:3,[2]]"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "    2\n",
       "0   2\n",
       "1   5\n",
       "2   8\n",
       "3  11"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 36
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "source": [
    "lianjia_df = pd.read_csv(r'D:/DeskTop-D/数据分析学习/数据分析代码/数据分析代码/03pandas源码及文件/pandas源码及文件/源码/作业参考答案/lianjia.csv')\r\n",
    "lianjia_df.head()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "  Direction Elevator      Floor     Garden  Id Layout   Price Region  \\\n",
       "0        南北      无电梯   低楼层(共6层)        翠竹苑   0   3室1厅   365.0     浦东   \n",
       "1         南      有电梯  低楼层(共36层)        百汇园   1   3室2厅  1449.0     徐汇   \n",
       "2        南北      有电梯  中楼层(共26层)  仁恒河滨城(二期)   2   3室2厅  1630.0     浦东   \n",
       "3         南      有电梯  高楼层(共30层)     财富海景花园   3   3室2厅  2000.0     浦东   \n",
       "4         东      有电梯  中楼层(共26层)      仁恒滨江园   4   3室2厅  1360.0     浦东   \n",
       "\n",
       "  Renovation    Size    Year  \n",
       "0         简装   77.84  1995.0  \n",
       "1         精装   145.2  1995.0  \n",
       "2         精装  161.94  1995.0  \n",
       "3         精装     185  1995.0  \n",
       "4         精装  130.41  1995.0  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>翠竹苑</td>\n",
       "      <td>0</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>365.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>简装</td>\n",
       "      <td>77.84</td>\n",
       "      <td>1995.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>低楼层(共36层)</td>\n",
       "      <td>百汇园</td>\n",
       "      <td>1</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1449.0</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>精装</td>\n",
       "      <td>145.2</td>\n",
       "      <td>1995.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南北</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>仁恒河滨城(二期)</td>\n",
       "      <td>2</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1630.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>161.94</td>\n",
       "      <td>1995.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高楼层(共30层)</td>\n",
       "      <td>财富海景花园</td>\n",
       "      <td>3</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>185</td>\n",
       "      <td>1995.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>东</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>仁恒滨江园</td>\n",
       "      <td>4</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1360.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>130.41</td>\n",
       "      <td>1995.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 41
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "source": [
    "lianjia_df.index\r\n",
    "lianjia_df.columns\r\n",
    "lianjia_df.head()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "  Direction Elevator      Floor     Garden  Id Layout   Price Region  \\\n",
       "0        南北      无电梯   低楼层(共6层)        翠竹苑   0   3室1厅   365.0     浦东   \n",
       "1         南      有电梯  低楼层(共36层)        百汇园   1   3室2厅  1449.0     徐汇   \n",
       "2        南北      有电梯  中楼层(共26层)  仁恒河滨城(二期)   2   3室2厅  1630.0     浦东   \n",
       "3         南      有电梯  高楼层(共30层)     财富海景花园   3   3室2厅  2000.0     浦东   \n",
       "4         东      有电梯  中楼层(共26层)      仁恒滨江园   4   3室2厅  1360.0     浦东   \n",
       "\n",
       "  Renovation    Size    Year  state  \n",
       "0         简装   77.84  1995.0      0  \n",
       "1         精装   145.2  1995.0      0  \n",
       "2         精装  161.94  1995.0      0  \n",
       "3         精装     185  1995.0      0  \n",
       "4         精装  130.41  1995.0      0  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "      <th>state</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>翠竹苑</td>\n",
       "      <td>0</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>365.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>简装</td>\n",
       "      <td>77.84</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>低楼层(共36层)</td>\n",
       "      <td>百汇园</td>\n",
       "      <td>1</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1449.0</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>精装</td>\n",
       "      <td>145.2</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南北</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>仁恒河滨城(二期)</td>\n",
       "      <td>2</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1630.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>161.94</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高楼层(共30层)</td>\n",
       "      <td>财富海景花园</td>\n",
       "      <td>3</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>185</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>东</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>仁恒滨江园</td>\n",
       "      <td>4</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1360.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>130.41</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 46
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "source": [
    "# 调整索引顺序\r\n",
    "lianjia_df[[\"Region\",\"Garden\",\"Layout\",\"Floor\",\"Year\",\"Size\",\"Elevator\",\"Direction\",\"Renovation\",\"Price\"]].head()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "  Region     Garden Layout      Floor    Year    Size Elevator Direction  \\\n",
       "0     浦东        翠竹苑   3室1厅   低楼层(共6层)  1995.0   77.84      无电梯        南北   \n",
       "1     徐汇        百汇园   3室2厅  低楼层(共36层)  1995.0   145.2      有电梯         南   \n",
       "2     浦东  仁恒河滨城(二期)   3室2厅  中楼层(共26层)  1995.0  161.94      有电梯        南北   \n",
       "3     浦东     财富海景花园   3室2厅  高楼层(共30层)  1995.0     185      有电梯         南   \n",
       "4     浦东      仁恒滨江园   3室2厅  中楼层(共26层)  1995.0  130.41      有电梯         东   \n",
       "\n",
       "  Renovation   Price  \n",
       "0         简装   365.0  \n",
       "1         精装  1449.0  \n",
       "2         精装  1630.0  \n",
       "3         精装  2000.0  \n",
       "4         精装  1360.0  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Region</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Year</th>\n",
       "      <th>Size</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Direction</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>浦东</td>\n",
       "      <td>翠竹苑</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>77.84</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>南北</td>\n",
       "      <td>简装</td>\n",
       "      <td>365.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>徐汇</td>\n",
       "      <td>百汇园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>低楼层(共36层)</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>145.2</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>1449.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>浦东</td>\n",
       "      <td>仁恒河滨城(二期)</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>161.94</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>南北</td>\n",
       "      <td>精装</td>\n",
       "      <td>1630.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>浦东</td>\n",
       "      <td>财富海景花园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>高楼层(共30层)</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>185</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>南</td>\n",
       "      <td>精装</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>浦东</td>\n",
       "      <td>仁恒滨江园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>130.41</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>东</td>\n",
       "      <td>精装</td>\n",
       "      <td>1360.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 87
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "source": [
    "import random\r\n",
    "states = [0,1]\r\n",
    "column_count = lianjia_df.shape[0]\r\n",
    "lianjia_df[\"state\"] = [random.choice(states) for x in range(column_count)]\r\n",
    "lianjia_df.head()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "  Direction Elevator      Floor     Garden Layout Region   Price Renovation  \\\n",
       "0        南北      无电梯   低楼层(共6层)        翠竹苑   3室1厅     浦东   365.0         简装   \n",
       "1         南      有电梯  低楼层(共36层)        百汇园   3室2厅     徐汇  1449.0         精装   \n",
       "2        南北      有电梯  中楼层(共26层)  仁恒河滨城(二期)   3室2厅     浦东  1630.0         精装   \n",
       "3         南      有电梯  高楼层(共30层)     财富海景花园   3室2厅     浦东  2000.0         精装   \n",
       "4         东      有电梯  中楼层(共26层)      仁恒滨江园   3室2厅     浦东  1360.0         精装   \n",
       "\n",
       "     Size    Year  state  \n",
       "0   77.84  1995.0      1  \n",
       "1   145.2  1995.0      1  \n",
       "2  161.94  1995.0      0  \n",
       "3     185  1995.0      0  \n",
       "4  130.41  1995.0      0  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Region</th>\n",
       "      <th>Price</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "      <th>state</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>翠竹苑</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>浦东</td>\n",
       "      <td>365.0</td>\n",
       "      <td>简装</td>\n",
       "      <td>77.84</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>低楼层(共36层)</td>\n",
       "      <td>百汇园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>1449.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>145.2</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南北</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>仁恒河滨城(二期)</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>浦东</td>\n",
       "      <td>1630.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>161.94</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高楼层(共30层)</td>\n",
       "      <td>财富海景花园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>浦东</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>185</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>东</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>仁恒滨江园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>浦东</td>\n",
       "      <td>1360.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>130.41</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 90
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "source": [
    "# 删除id这一列\r\n",
    "lianjia_df.drop(axis=0,columns=\"Id\",inplace=True)\r\n",
    "lianjia_df.head()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "  Direction Elevator      Floor     Garden Layout   Price Region Renovation  \\\n",
       "0        南北      无电梯   低楼层(共6层)        翠竹苑   3室1厅   365.0     浦东         简装   \n",
       "1         南      有电梯  低楼层(共36层)        百汇园   3室2厅  1449.0     徐汇         精装   \n",
       "2        南北      有电梯  中楼层(共26层)  仁恒河滨城(二期)   3室2厅  1630.0     浦东         精装   \n",
       "3         南      有电梯  高楼层(共30层)     财富海景花园   3室2厅  2000.0     浦东         精装   \n",
       "4         东      有电梯  中楼层(共26层)      仁恒滨江园   3室2厅  1360.0     浦东         精装   \n",
       "\n",
       "     Size    Year  state  \n",
       "0   77.84  1995.0      0  \n",
       "1   145.2  1995.0      0  \n",
       "2  161.94  1995.0      0  \n",
       "3     185  1995.0      0  \n",
       "4  130.41  1995.0      0  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "      <th>state</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>翠竹苑</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>365.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>简装</td>\n",
       "      <td>77.84</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>低楼层(共36层)</td>\n",
       "      <td>百汇园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1449.0</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>精装</td>\n",
       "      <td>145.2</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南北</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>仁恒河滨城(二期)</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1630.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>161.94</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>高楼层(共30层)</td>\n",
       "      <td>财富海景花园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>185</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>东</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>中楼层(共26层)</td>\n",
       "      <td>仁恒滨江园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>1360.0</td>\n",
       "      <td>浦东</td>\n",
       "      <td>精装</td>\n",
       "      <td>130.41</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 47
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "source": [
    "# 4. 查找楼层小于7的房子(这里查找4 5 6 层)\r\n",
    "def extract_low_floor(floors):\r\n",
    "    low_floors = []\r\n",
    "    for floor in floors:\r\n",
    "        if \"共6层\" in floor or \"共5层\" in floor or \"共4层\" in floor:\r\n",
    "            low_floors.append(True)\r\n",
    "        else:\r\n",
    "            low_floors.append(False)\r\n",
    "    return low_floors\r\n",
    "low_floor_lianjia_df = lianjia_df[extract_low_floor(lianjia_df['Floor'])]\r\n",
    "low_floor_lianjia_df.head()"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   Direction Elevator     Floor    Garden Layout Region  Price Renovation  \\\n",
       "0         南北      无电梯  低楼层(共6层)       翠竹苑   3室1厅     浦东  365.0         简装   \n",
       "9         南北      无电梯  低楼层(共6层)       金水苑   3室2厅     奉贤  240.0         简装   \n",
       "11         南      无电梯  中楼层(共5层)  绿野香洲(公寓)   3室2厅     闵行  660.0         精装   \n",
       "24         南      无电梯  高楼层(共6层)       长兴坊   3室1厅     徐汇  515.0         精装   \n",
       "25         南      无电梯  高楼层(共6层)       锦绣苑   2室2厅     浦东  660.0         精装   \n",
       "\n",
       "      Size    Year  state  \n",
       "0    77.84  1995.0      1  \n",
       "9   133.62  1995.0      0  \n",
       "11  107.53  1995.0      0  \n",
       "24   83.88  1995.0      1  \n",
       "25   98.18  1995.0      1  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Region</th>\n",
       "      <th>Price</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "      <th>state</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>翠竹苑</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>浦东</td>\n",
       "      <td>365.0</td>\n",
       "      <td>简装</td>\n",
       "      <td>77.84</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>金水苑</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>奉贤</td>\n",
       "      <td>240.0</td>\n",
       "      <td>简装</td>\n",
       "      <td>133.62</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>中楼层(共5层)</td>\n",
       "      <td>绿野香洲(公寓)</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>闵行</td>\n",
       "      <td>660.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>107.53</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>高楼层(共6层)</td>\n",
       "      <td>长兴坊</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>515.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>83.88</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>高楼层(共6层)</td>\n",
       "      <td>锦绣苑</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>浦东</td>\n",
       "      <td>660.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>98.18</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 149
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "source": [
    "low_floor_line_count = low_floor_lianjia_df.shape[0]\r\n",
    "low_floor_lianjia_df.loc[0:,'Elevator'] = '无电梯'\r\n",
    "low_floor_lianjia_df"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "C:\\Users\\10622\\anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:965: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  self.obj[item] = s\n"
     ]
    },
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "     Direction Elevator      Floor  Garden Layout Region   Price Renovation  \\\n",
       "0           南北      无电梯   低楼层(共6层)     翠竹苑   3室1厅     浦东   365.0         简装   \n",
       "1            南      无电梯  低楼层(共36层)     百汇园   3室2厅     徐汇  1449.0         精装   \n",
       "9           南北      无电梯   低楼层(共6层)     金水苑   3室2厅     奉贤   240.0         简装   \n",
       "14           南      无电梯  低楼层(共11层)  万科城花新园   3室2厅     闵行   860.0         精装   \n",
       "15           南      无电梯  低楼层(共18层)   鸿凯湾绿苑   3室2厅     长宁  1090.0         简装   \n",
       "...        ...      ...        ...     ...    ...    ...     ...        ...   \n",
       "1699         南      无电梯  低楼层(共16层)  万邦都市花园   3室2厅     浦东   900.0         简装   \n",
       "1700         南      无电梯   低楼层(共6层)    汇成五村   1室1厅     徐汇   235.0         毛坯   \n",
       "1703        南北      无电梯  低楼层(共22层)     徐汇苑   3室2厅     徐汇  2120.0         精装   \n",
       "1707        南北      无电梯   低楼层(共6层)    梅陇四村   2室1厅     徐汇   320.0         其他   \n",
       "1709         南      无电梯  低楼层(共11层)    华泾绿苑   1室1厅     徐汇   310.0         毛坯   \n",
       "\n",
       "        Size    Year  state  \n",
       "0      77.84  1995.0      1  \n",
       "1      145.2  1995.0      1  \n",
       "9     133.62  1995.0      0  \n",
       "14    129.73  1995.0      1  \n",
       "15    120.76  1995.0      0  \n",
       "...      ...     ...    ...  \n",
       "1699   127.3  1995.0      0  \n",
       "1700    36.2  1995.0      0  \n",
       "1703     207  1995.0      0  \n",
       "1707   64.58  1995.0      1  \n",
       "1709   64.56  1995.0      0  \n",
       "\n",
       "[579 rows x 11 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Region</th>\n",
       "      <th>Price</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "      <th>state</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>翠竹苑</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>浦东</td>\n",
       "      <td>365.0</td>\n",
       "      <td>简装</td>\n",
       "      <td>77.84</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共36层)</td>\n",
       "      <td>百汇园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>1449.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>145.2</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>金水苑</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>奉贤</td>\n",
       "      <td>240.0</td>\n",
       "      <td>简装</td>\n",
       "      <td>133.62</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共11层)</td>\n",
       "      <td>万科城花新园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>闵行</td>\n",
       "      <td>860.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>129.73</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共18层)</td>\n",
       "      <td>鸿凯湾绿苑</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>长宁</td>\n",
       "      <td>1090.0</td>\n",
       "      <td>简装</td>\n",
       "      <td>120.76</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1699</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共16层)</td>\n",
       "      <td>万邦都市花园</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>浦东</td>\n",
       "      <td>900.0</td>\n",
       "      <td>简装</td>\n",
       "      <td>127.3</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1700</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>汇成五村</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>235.0</td>\n",
       "      <td>毛坯</td>\n",
       "      <td>36.2</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1703</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共22层)</td>\n",
       "      <td>徐汇苑</td>\n",
       "      <td>3室2厅</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>2120.0</td>\n",
       "      <td>精装</td>\n",
       "      <td>207</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1707</th>\n",
       "      <td>南北</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共6层)</td>\n",
       "      <td>梅陇四村</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>320.0</td>\n",
       "      <td>其他</td>\n",
       "      <td>64.58</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1709</th>\n",
       "      <td>南</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>低楼层(共11层)</td>\n",
       "      <td>华泾绿苑</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>徐汇</td>\n",
       "      <td>310.0</td>\n",
       "      <td>毛坯</td>\n",
       "      <td>64.56</td>\n",
       "      <td>1995.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>579 rows × 11 columns</p>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 99
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "source": [
    "s1 = pd.Series(np.arange(4),index=['a','b','c','d'])\r\n",
    "s2 = pd.Series(np.arange(5),index=['a','b','c','d','e'])"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "source": [
    "s1 + s2"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "a    0.0\n",
       "b    2.0\n",
       "c    4.0\n",
       "d    6.0\n",
       "e    NaN\n",
       "dtype: float64"
      ]
     },
     "metadata": {},
     "execution_count": 111
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "source": [
    "s1.add(s2,fill_values=0)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "a    0.0\n",
       "b    2.0\n",
       "c    4.0\n",
       "d    6.0\n",
       "e    4.0\n",
       "dtype: float64"
      ]
     },
     "metadata": {},
     "execution_count": 114
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "source": [
    "arr = np.arange(12).reshape(3,4)\r\n",
    "arr\r\n",
    "arr - arr[0] # 广播"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "array([[0, 0, 0, 0],\n",
       "       [4, 4, 4, 4],\n",
       "       [8, 8, 8, 8]])"
      ]
     },
     "metadata": {},
     "execution_count": 116
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "source": [
    "df1 = pd.DataFrame(data={0:[1,2,3,4],1:[5,6,7,8],3:[12,3,4,5]})\r\n",
    "s3 = df1.iloc[0]\r\n",
    "s3"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "0     1\n",
       "1     5\n",
       "3    12\n",
       "Name: 0, dtype: int64"
      ]
     },
     "metadata": {},
     "execution_count": 124
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "source": [
    "df1 - s3"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   0  1  3\n",
       "0  0  0  0\n",
       "1  1  1 -9\n",
       "2  2  2 -8\n",
       "3  3  3 -7"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>-9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>-8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>-7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 125
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "source": [
    "df = pd.DataFrame(np.random.randn(5,4))\r\n",
    "df"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "          0         1         2         3\n",
       "0  0.487521  1.200102 -0.887434 -0.458940\n",
       "1  0.016052  0.839797  0.665284 -0.302988\n",
       "2 -0.005707 -0.526835  0.510555  0.380304\n",
       "3 -0.185667  1.362727 -0.966484 -2.243040\n",
       "4  1.355231  0.377221  0.449581 -0.427795"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.487521</td>\n",
       "      <td>1.200102</td>\n",
       "      <td>-0.887434</td>\n",
       "      <td>-0.458940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.016052</td>\n",
       "      <td>0.839797</td>\n",
       "      <td>0.665284</td>\n",
       "      <td>-0.302988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>-0.005707</td>\n",
       "      <td>-0.526835</td>\n",
       "      <td>0.510555</td>\n",
       "      <td>0.380304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>-0.185667</td>\n",
       "      <td>1.362727</td>\n",
       "      <td>-0.966484</td>\n",
       "      <td>-2.243040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.355231</td>\n",
       "      <td>0.377221</td>\n",
       "      <td>0.449581</td>\n",
       "      <td>-0.427795</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 126
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "source": [
    "np.abs(df) # 可以直接使用numpy的函数\r\n",
    "f = lambda x:x.max()\r\n",
    "df.apply(f) # 主义轴的方向， 默认axis=0 列 apply是将函数应用到数据上\r\n",
    "np.max(df,axis=1)\r\n"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "0    1.200102\n",
       "1    0.839797\n",
       "2    0.510555\n",
       "3    1.362727\n",
       "4    1.355231\n",
       "dtype: float64"
      ]
     },
     "metadata": {},
     "execution_count": 132
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "source": [
    "# 索引排序\r\n",
    "s1 = pd.Series(np.arange(4),index=list('dbca'))\r\n",
    "s1\r\n",
    "s1.sort_index() # 默认升序"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "a    3\n",
       "b    1\n",
       "c    2\n",
       "d    0\n",
       "dtype: int32"
      ]
     },
     "metadata": {},
     "execution_count": 134
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "source": [
    "pd1 = pd.DataFrame(np.arange(12).reshape(4,3),index=list('bdca'),columns=list('BCA'))\r\n",
    "pd1\r\n",
    "pd1.sort_index() # 按照行排序\r\n",
    "pd1.sort_index(axis=1) # 按照列排序"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "    A  B   C\n",
       "b   2  0   1\n",
       "d   5  3   4\n",
       "c   8  6   7\n",
       "a  11  9  10"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>8</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>11</td>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 140
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "source": [
    "s1.sort_values() # 根据值的大小排序 当有缺失值时，会默认排在最后\r\n",
    "pd1.sort_values(by='A') #按列排序\r\n",
    "pd1.sort_values(by=['A','B']) # 按多列排序"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   B   C   A\n",
       "b  0   1   2\n",
       "d  3   4   5\n",
       "c  6   7   8\n",
       "a  9  10  11"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>A</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 143
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "source": [
    "s1 = pd.Series([2,6,8,9,3,6])\r\n",
    "s1\r\n",
    "s2 = s1.unique() # 返回一个数组 将值变为唯一的\r\n",
    "s2\r\n",
    "s1.isin([8]) #判断8是否存在于s1中  作用对象为series,dataframe 不能用于数组，字符串\r\n",
    "pd1.isin([8,1,2,3,5])"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "       B      C      A\n",
       "b  False   True   True\n",
       "d   True  False   True\n",
       "c  False  False   True\n",
       "a  False  False  False"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>A</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 151
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "source": [
    "pd1.iloc[1,[1]] = np.nan #将某个位置设置为nan\r\n",
    "pd1\r\n",
    "pd1.isnull() #判断是否存在缺失值\r\n",
    "pd1.dropna() #丢弃缺失值 直接把这一行全部舍弃\r\n",
    "pd1.dropna(axis=1) # 直接把这一列丢弃"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   B   A (0, 1)\n",
       "b  0   2    NaN\n",
       "d  3   5    NaN\n",
       "c  6   8    NaN\n",
       "a  9  11    NaN"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>B</th>\n",
       "      <th>A</th>\n",
       "      <th>(0, 1)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>d</th>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>9</td>\n",
       "      <td>11</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 177
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "source": [
    "pd1.fillna(-1.) # 填空缺失值\r\n",
    "pd1.sum() # 返回列的和  指定axis=1按行求和\r\n",
    "pd1.sum(axis=1) # Nan会当做0来处理\r\n",
    "pd1.mean() # 求列的平均值\r\n",
    "pd1.mean(axis=1)"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "b     1.0\n",
       "d     4.0\n",
       "c     7.0\n",
       "a    10.0\n",
       "dtype: float64"
      ]
     },
     "metadata": {},
     "execution_count": 183
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "source": [
    "pd1.describe() # 描述汇总"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "              B          A\n",
       "count  4.000000   4.000000\n",
       "mean   4.500000   6.500000\n",
       "std    3.872983   3.872983\n",
       "min    0.000000   2.000000\n",
       "25%    2.250000   4.250000\n",
       "50%    4.500000   6.500000\n",
       "75%    6.750000   8.750000\n",
       "max    9.000000  11.000000"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>B</th>\n",
       "      <th>A</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>4.000000</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>4.500000</td>\n",
       "      <td>6.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>3.872983</td>\n",
       "      <td>3.872983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>2.250000</td>\n",
       "      <td>4.250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>4.500000</td>\n",
       "      <td>6.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>6.750000</td>\n",
       "      <td>8.750000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>9.000000</td>\n",
       "      <td>11.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "metadata": {},
     "execution_count": 184
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.7.6",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.6 64-bit ('base': conda)"
  },
  "interpreter": {
   "hash": "af997f310b38b8fff913e3035512343e167e2ca0aa226bb6d1eaa902db614b07"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}